package com.taorenqi.data.service;

import android.content.Context;

import com.taorenqi.data.common.BasePageableResponse;
import com.taorenqi.data.entity.login.CodeDataEntity;
import com.taorenqi.data.entity.login.LoginEntity;

import rx.Observable;
import rx.Subscriber;

/**
 * Created by Administrator on 2017-06-12.
 */

public class LoginDataHttpRequest extends HttpRequest {

    private static LoginDataHttpRequest instants;
    private LoginDataService service;

    private LoginDataHttpRequest(Context context) {
        super(context);
        service = retrofit.create(LoginDataService.class);
    }

    public static LoginDataHttpRequest getInstance(Context context){
        if (instants == null){
            instants = new LoginDataHttpRequest(context);
        }

        return instants;
    }


    /**
     * 用于取得登录数据
     *
     * @param subscriber 由调用者传过来的观察者对象
     * @param mobile      手机号
     * @param password    密码
     * @param device      设备
     */
    public void postLogin(Subscriber<BasePageableResponse<LoginEntity>> subscriber, String mobile, String password, String device,String sign)  {

        Observable observable = service.postLogin(mobile, password,device,sign)
                .map(new HttpResultFunc<BasePageableResponse<LoginEntity>>());

        toSubscribe(observable, subscriber);
    }

    /**
     * 用于检查是否注册
     *
     * @param subscriber 由调用者传过来的观察者对象
     * @param mobile      手机号
     * @param sign
     */
    public void postCheckReg(Subscriber<BasePageableResponse<CodeDataEntity>> subscriber, String mobile,String sign) {

        Observable observable = service.postCheckReg(mobile,sign)
                .map(new HttpResultFunc<BasePageableResponse<CodeDataEntity>>());

        toSubscribe(observable, subscriber);
    }

    /**
     * 用于发送验证码
     *
     * @param subscriber 由调用者传过来的观察者对象
     * @param mobile      手机号
     * @param sign
     */
    public void postSendSms(Subscriber<BasePageableResponse<CodeDataEntity>> subscriber, String mobile,int reg,String sign) {

        Observable observable = service.postSendSms(mobile,reg,sign)
                .map(new HttpResultFunc<BasePageableResponse<CodeDataEntity>>());

        toSubscribe(observable, subscriber);
    }

    /**
     * 修改手机号
     *
     * @param subscriber 由调用者传过来的观察者对象
     * @param mobile      手机号
     * @param sign
     */
    public void postModifyPhone(Subscriber<BasePageableResponse<CodeDataEntity>> subscriber, String mobile,String vcode,String msgToken,String sign) {

        Observable observable = service.postModifyPhone(mobile,vcode,msgToken,sign)
                .map(new HttpResultFunc<BasePageableResponse<CodeDataEntity>>());

        toSubscribe(observable, subscriber);
    }

    /**
     * 修改密码
     *
     * @param subscriber 由调用者传过来的观察者对象
     * @param newPassword      手机号
     * @param sign
     */
    public void postModifyPwd(Subscriber<BasePageableResponse<CodeDataEntity>> subscriber, String password,String newPassword,String sign) {

        Observable observable = service.postModifyPwd(password,newPassword,sign)
                .map(new HttpResultFunc<BasePageableResponse<CodeDataEntity>>());

        toSubscribe(observable, subscriber);
    }


    /**
     * 用于取得登录数据
     *
     * @param subscriber 由调用者传过来的观察者对象
     * @param
     * @param
     * @param
     */
    public void postCompleteInfo(Subscriber<BasePageableResponse<LoginEntity>> subscriber, String name,
                                 String sex, String wangwang,String weixin,String qq,String companyname,
                                 String companytel,String companyemail,String sign)  {

        Observable observable = service.postCompleteInfo(name, sex,wangwang,weixin,qq,companyname,companytel,companyemail,sign)
                .map(new HttpResultFunc<BasePageableResponse<LoginEntity>>());

        toSubscribe(observable, subscriber);
    }
}
